package com.badibadi.fragment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import com.badibadi.abcpinying.SortModel;
import com.badibadi.activity.ChatActivity;
import com.badibadi.activity.ChatSettingActivity;
import com.badibadi.activity.ClubMemberActivity;
import com.badibadi.infos.Chat_Hestory_person_Model;
import com.badibadi.infos.Chat_Message_Model;
import com.badibadi.infos.Main_Chat_Hestory_Message_Model;
import com.badibadi.infos.Results;
import com.badibadi.infos.friendShow_Model;
import com.badibadi.infos.infoUserModle;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MySharePreferences;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.Utils;
import com.badibadi.socket.Send_Geshi_Tool;
import com.badibadi.socket.Temp_New_Message_Model;
import com.badibadi.uniclubber.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.view.my_view.PaoPao_Button;
import com.view.my_view.PaoPao_ImageView;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class AfterLandingMyHomePageChatMessageFragment extends BaseFragment {
	String yuying = "/Public/music";
	private ListView mListView;
	// Handler mHandler;
	private ChatMessageAdapter mAdapter;

	private Results results2, results;
	private Chat_Message_Model message_Model;
	private List<friendShow_Model> show_Models;
	private List<Temp_New_Message_Model> shaixuan_data, temp;
	private List<Chat_Hestory_person_Model> person_Models;
	private boolean judge = false;
	private List<List<Temp_New_Message_Model>> only_data_s;
	private List<Main_Chat_Hestory_Message_Model> chat_Hestory_Message_Models,
			hestory_Message_Models;
	private Calendar calendar;

	private Button delete_friends_list_cancle, delete_friends_list_delete;// 删除窗口的按钮
	private AlertDialog.Builder builder;
	private Dialog dialog;
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 2:
				Utils.ExitPrgress(getActivity());
				try {
					listBody();
				} catch (Exception e) {
					// TODO: handle exception
				}

				// only_data_s.clear();
				// only_data_s = shaixuan4(shaixuan2(show_Models),
				// shaixuan3(shaixuan2(show_Models)));
				// mAdapter.notifyDataSetChanged();
				// temp.clear();
				// temp = shaixuan3(shaixuan2(show_Models));
				// for (int i = 0; i < temp.size(); i++) {
				// preferences.puts("name", temp.get(i).getNickName(), "head",
				// temp.get(i).getHead(), "message", temp.get(i)
				// .getMes(), "time", temp.get(i).getTime());
				// }
				break;
			case 3:
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xa10));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 4:
				Utils.ExitPrgress(getActivity());
				try {
					judge = true;
					if (person_Models.size() > 0) {
						chat_Hestory_Message_Models.clear();
						chat_Hestory_Message_Models = jiehe(person_Models,
								show_Models);
						//    
						// + chat_Hestory_Message_Models.toString());
					}
					hestory_Message_Models = shaixuan8(shaixuan7(shaixuan6(shaixuan5(
							chat_Hestory_Message_Models,
							shaixuan4(shaixuan2(show_Models),
									shaixuan3(shaixuan2(show_Models)))))));
					//    
					// hestory_Message_Models.toString());
					mAdapter.notifyDataSetChanged();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 6:
				// hestory_Message_Models.clear();
				try {
//					   
//							+ chat_Hestory_Message_Models.toString());
					hestory_Message_Models = shaixuan8(shaixuan7(shaixuan6(shaixuan5(
							chat_Hestory_Message_Models,
							shaixuan4(shaixuan2(show_Models),
									shaixuan3(shaixuan2(show_Models)))))));
					//    
					// hestory_Message_Models.toString());
					mAdapter.notifyDataSetChanged();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 7:
				Utils.ExitPrgress(getActivity());
				friendShow();
				break;
			default:
				break;
			}
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	// private List<Main_Chat_Hestory_Message_Model> fanxu(
	// List<Main_Chat_Hestory_Message_Model> person_Models) {
	// List<Main_Chat_Hestory_Message_Model> models_1 = new
	// ArrayList<Main_Chat_Hestory_Message_Model>();
	// for (int i = person_Models.size() - 1; i > 0; --i) {
	// models_1.add(person_Models.get(i));
	// }
	// return person_Models;
	// }

	private List<Main_Chat_Hestory_Message_Model> jiehe(
			List<Chat_Hestory_person_Model> person_Models,
			List<friendShow_Model> show_Mod) {
		// List<List<Temp_New_Message_Model>> only_data_ss = new
		// ArrayList<List<Temp_New_Message_Model>>();
		List<Main_Chat_Hestory_Message_Model> chats = new ArrayList<Main_Chat_Hestory_Message_Model>();
		for (int i = 0; i < person_Models.size(); i++) {
			Main_Chat_Hestory_Message_Model message_ = new Main_Chat_Hestory_Message_Model();
			List<Temp_New_Message_Model> list = new ArrayList<Temp_New_Message_Model>();
			Temp_New_Message_Model message_Model = new Temp_New_Message_Model();
			message_Model.setId(person_Models.get(i).getOtherUid());
			message_Model.setMes(person_Models.get(i).getMsg());
			message_Model.setNickName(person_Models.get(i).getName());
			message_Model.setTime_("" + person_Models.get(i).getTime());
			message_Model.setMes_num("0");
			try {
				message_Model.setTime(Utils.jisuan(
						Utils.Get_System_Time("yyyy-MM-dd HH:mm:ss"),
						person_Models.get(i).getTime()));
			} catch (Exception e) {
				// TODO Auto-generated catch block
//				   
				   
			}
			for (int m = 0; m < show_Mod.size(); m++) {
				if (show_Mod.get(m).getFriends() != null
						&& !show_Mod.get(m).getFriends().isEmpty()) {
					for (int n = 0; n < show_Mod.get(m).getFriends().size(); n++) {
						if (person_Models
								.get(i)
								.getOtherUid()
								.equals(show_Mod.get(m).getFriends().get(n)
										.getId())) {
							message_Model.setHead(show_Mod.get(m).getFriends()
									.get(n).getHead());
							message_Model.setIs_blacklist(show_Mod.get(m)
									.getIs_blacklist());
						}
					}
				}

			}
			list.add(message_Model);
			message_.setModels(list);
			message_.setSum("0");
			chats.add(message_);
			// only_data_ss.add(list);
		}
//		   
		return chats;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(
				R.layout.fragment_adapter_chat_message_import_layout, null);
		// Send_Geshi_Tool.chat_Message_Models;
		calendar = Calendar.getInstance();
		mListView = (ListView) view
				.findViewById(R.id.fragment_adapter_chat_message_xlistView);
		shaixuan_data = new ArrayList<Temp_New_Message_Model>();
		// Only_data = new ArrayList<Temp_New_Message_Model>();
		temp = new ArrayList<Temp_New_Message_Model>();
		only_data_s = new ArrayList<List<Temp_New_Message_Model>>();
		person_Models = new ArrayList<Chat_Hestory_person_Model>();
		chat_Hestory_Message_Models = new ArrayList<Main_Chat_Hestory_Message_Model>();
		hestory_Message_Models = new ArrayList<Main_Chat_Hestory_Message_Model>();
		mAdapter = new ChatMessageAdapter();
		mListView.setAdapter(mAdapter);
		mListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				hestory_Message_Models.get(position).setSum("0");
				mAdapter.notifyDataSetChanged();
				Intent intent = new Intent(getActivity(), ChatActivity.class);
				intent.putExtra(
						"id",
						hestory_Message_Models
								.get(position)
								.getModels()
								.get(hestory_Message_Models.get(position)
										.getModels().size() - 1).getId());
				intent.putExtra(
						"name",
						hestory_Message_Models
								.get(position)
								.getModels()
								.get(hestory_Message_Models.get(position)
										.getModels().size() - 1).getNickName());
				intent.putExtra(
						"head",
						hestory_Message_Models
								.get(position)
								.getModels()
								.get(hestory_Message_Models.get(position)
										.getModels().size() - 1).getHead());
				startActivity(intent);
			}
		});
		mListView.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				ShowDialog(hestory_Message_Models
						.get(arg2)
						.getModels()
						.get(hestory_Message_Models.get(arg2).getModels()
								.size() - 1).getId());
				return true;
			}
		});
		friendShow();
		return view;
	}

	private void ShowDialog(String deleteUid) {
		builder = new AlertDialog.Builder(getActivity());
		builder.setView(Return_View(deleteUid));
		dialog = builder.show();
	}

	private View Return_View(final String deleteUid) {
		View view = null;
		LayoutInflater inflater = LayoutInflater.from(getActivity());
		view = inflater.inflate(R.layout.delete_friends_list_inter, null);
		delete_friends_list_cancle = (Button) view
				.findViewById(R.id.delete_friends_list_cancle);
		delete_friends_list_delete = (Button) view
				.findViewById(R.id.delete_friends_list_delete);
		delete_friends_list_delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				deleteBody(deleteUid);
				dialog.dismiss();
			}
		});
		delete_friends_list_cancle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialog.dismiss();
			}
		});
		return view;
	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Send_Geshi_Tool.public_new_mes_handler = handler;
		if (judge) {
			friendShow();
			// hestory_Message_Models = shaixuan6(shaixuan5(
			// chat_Hestory_Message_Models,
			// shaixuan4(shaixuan2(show_Models),
			// shaixuan3(shaixuan2(show_Models)))));
			// mAdapter.notifyDataSetChanged();
			Send_Geshi_Tool.new_message_num = Send_Geshi_Tool.chat_Message_Models
					.size();
			Send_Geshi_Tool.public_new_mes_num_handler.sendEmptyMessage(6);
			//    
			// Send_Geshi_Tool.chat_Message_Models.size());
		} else {
			//    
		}
	}

	/**
	 * 筛选第一层(将新消息整理到Temp_New_Message_Model类中)
	 * 
	 * @param id
	 *            (新信息发送者id)
	 * @param show_Models
	 *            (所有朋友列表数据)
	 * @return
	 */
	private Temp_New_Message_Model shaixuan1(String id,
			List<friendShow_Model> show_Models) {
		Temp_New_Message_Model message_Model = null;
		for (int i = 0; i < show_Models.size(); i++) {
			if (show_Models.get(i).getFriends() != null
					&& !show_Models.get(i).getFriends().isEmpty()) {
				for (int j = 0; j < show_Models.get(i).getFriends().size(); j++) {
					if (show_Models.get(i).getFriends().get(j).getId()
							.equals(id)) {
						message_Model = new Temp_New_Message_Model();
						message_Model.setHead(show_Models.get(i).getFriends()
								.get(j).getHead());
						message_Model.setId(show_Models.get(i).getFriends()
								.get(j).getId());
						message_Model.setMes("");
						message_Model.setNickName(show_Models.get(i)
								.getFriends().get(j).getNickName());
						message_Model.setTime("");
						return message_Model;
					}
				}
			}
		}
		return null;
	}

	/**
	 * 筛选第二层(将 第一层筛选出的数据整理出来，并全部赋值)
	 * 
	 * @param show_Models
	 *            (所有朋友列表数据)
	 * @return
	 */
	private List<Temp_New_Message_Model> shaixuan2(
			List<friendShow_Model> show_Models) {
		List<Temp_New_Message_Model> shaixuan_da = new ArrayList<Temp_New_Message_Model>();
		Temp_New_Message_Model model = null;
		for (int i = 0; i < Send_Geshi_Tool.chat_Message_Models.size(); i++) {
			model = shaixuan1(Send_Geshi_Tool.chat_Message_Models.get(i)
					.getNew_mess_uid(), show_Models);// 筛选新消息都是谁发送的（会有重复的）
			if (model != null) {
				model.setMes(Send_Geshi_Tool.chat_Message_Models.get(i)
						.getChat_message());
				// model.setTime(Send_Geshi_Tool.chat_Message_Models.get(i)
				// .getChat_time());
				model.setTime(Utils.Get_Data(
						Utils.getStringMillis_quan(
								Send_Geshi_Tool.chat_Message_Models.get(i)
										.getChat_time(), calendar)
								+ "", "HH:mm", ""));
				// model.setTime(Send_Geshi_Tool.chat_Message_Models.get(i)
				// .getChat_time());
				//    
				// "时间是:"
				// + Send_Geshi_Tool.chat_Message_Models.get(i)
				// .getChat_time());
				model.setTime_(Utils.getStringMillis_quan(
						Send_Geshi_Tool.chat_Message_Models.get(i)
								.getChat_time(), calendar)
						+ "");
				shaixuan_da.add(model);
				//    ("有几个人推送消息");
			}
		}
		//    
		// "第二层:" + shaixuan_da.size() + " " + shaixuan_da.toString());
		return shaixuan_da;
	}

	/**
	 * 筛选第三层(将第二层数据进行筛选，过滤后，每个数据都只有唯一不重复的id)
	 * 
	 * @param shaixuan_data
	 *            (第二层的数据)
	 * @return
	 */
	private List<Temp_New_Message_Model> shaixuan3(
			List<Temp_New_Message_Model> shaixuan_data) {// 筛选出所有新消息中重复出现的好友
		for (int i = 0; i < shaixuan_data.size() - 1; i++) {
			for (int j = shaixuan_data.size() - 1; j > i; j--) {
				if (shaixuan_data.get(j).getId()
						.equals(shaixuan_data.get(i).getId())) {
					shaixuan_data.remove(j);
				}
			}
		}
		return shaixuan_data;
	}

	/**
	 * 筛选第四层(将第二层和第三层筛选的数据进行匹配和组合，使每条信息对应每个人并组合到一个列表中（注：返回值为适配器内所需数据 ）)
	 * (这个是新的聊天消息数据)
	 * 
	 * @param shaixuan_data
	 *            (第二层的数据)
	 * @param Only_data
	 *            (第三层数据)
	 * @return
	 */
	private List<Main_Chat_Hestory_Message_Model> shaixuan4(
			List<Temp_New_Message_Model> shaixuan_data,
			List<Temp_New_Message_Model> Only_data) {
		List<Main_Chat_Hestory_Message_Model> chats = new ArrayList<Main_Chat_Hestory_Message_Model>();
		for (int j = 0; j < Only_data.size(); j++) {
			List<Temp_New_Message_Model> temp = new ArrayList<Temp_New_Message_Model>();
			Main_Chat_Hestory_Message_Model message_Model = new Main_Chat_Hestory_Message_Model();
			int su = 0;
			for (int i = 0; i < shaixuan_data.size(); i++) {
				if (shaixuan_data.get(i).getId()
						.equals(Only_data.get(j).getId())) {
					++su;
					temp.add(shaixuan_data.get(i));
				}
			}
			message_Model.setSum(su + "");
			message_Model.setModels(temp);
			chats.add(message_Model);
			//    
		}
//		   
		return chats;
	}

	private List<Main_Chat_Hestory_Message_Model> shaixuan5(
			List<Main_Chat_Hestory_Message_Model> hestory_list,
			List<Main_Chat_Hestory_Message_Model> new_list) {
		List<Main_Chat_Hestory_Message_Model> chats = new ArrayList<Main_Chat_Hestory_Message_Model>();
		if ((hestory_list != null && hestory_list.size() > 0)
				&& (new_list == null || new_list.size() == 0)) {
//			   
			return hestory_list;
		} else if ((hestory_list == null || hestory_list.size() == 0)
				&& (new_list != null && new_list.size() > 0)) {
//			   
			return new_list;
		} else if ((hestory_list == null || hestory_list.size() == 0)
				&& (new_list == null || new_list.size() == 0)) {
//			   
			return chats;
		} else {
//			   
			for (int i = 0; i < hestory_list.size(); i++) {
				if (hestory_list.get(i).getModels() != null
						&& hestory_list.get(i).getModels().size() > 0) {
					for (int m = 0; m < new_list.size(); m++) {
						if (new_list.get(m).getModels() != null
								&& new_list.get(m).getModels().size() > 0) {
							if (hestory_list
									.get(i)
									.getModels()
									.get(hestory_list.get(i).getModels().size() - 1)
									.getId()
									.equals(new_list
											.get(m)
											.getModels()
											.get(new_list.get(m).getModels()
													.size() - 1).getId())) {
								new_list.get(m)
										.getModels()
										.get(new_list.get(m).getModels().size() - 1)
										.setIs_blacklist(
												hestory_list
														.get(i)
														.getModels()
														.get(hestory_list
																.get(i)
																.getModels()
																.size() - 1)
														.getIs_blacklist());// 将老数据里的是否是黑名单的判断参数获取到新数据中进行判断
								chats.add(new_list.get(m));
								// new_list.remove(m);
							} else {
								chats.add(hestory_list.get(i));
								// hestory_list.remove(i);
							}
						}
					}
				}
			}
		}

		return chats;
	}

	/**
	 * 二次筛选里面多余的数据（这步不知可省略，加上是没有错的）
	 * 
	 * @param list
	 * @return
	 */
	private List<Main_Chat_Hestory_Message_Model> shaixuan6(
			List<Main_Chat_Hestory_Message_Model> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			for (int j = list.size() - 1; j > i; j--) {
				if (list.get(j).getModels() != null
						&& list.get(j).getModels().size() > 0) {
					if (list.get(j)
							.getModels()
							.get(list.get(j).getModels().size() - 1)
							.getId()
							.equals(list.get(i).getModels()
									.get(list.get(i).getModels().size() - 1)
									.getId())) {
						list.remove(j);
					}
				}
			}
		}
		return list;
	}

	/**
	 * 根据聊天数据里的时间进行排序，最新的排在最上面
	 * 
	 * @param list
	 * @return
	 */
	private List<Main_Chat_Hestory_Message_Model> shaixuan7(
			List<Main_Chat_Hestory_Message_Model> list) {
		Main_Chat_Hestory_Message_Model temp = null;
		for (int i = list.size() - 1; i > 0; --i) {
			for (int j = 0; j < i; j++) {
				if (list.get(j).getModels().size() > 0) {
					if (!list.get(j).getModels()
							.get(list.get(j).getModels().size() - 1).getTime_()
							.equals("null")
							&& !list.get(j + 1)
									.getModels()
									.get(list.get(j + 1).getModels().size() - 1)
									.getTime_().equals("null")) {
						long time1 = Long.valueOf(list.get(j).getModels()
								.get(list.get(j).getModels().size() - 1)
								.getTime_());
						long time2 = Long.valueOf(list.get(j + 1).getModels()
								.get(list.get(j + 1).getModels().size() - 1)
								.getTime_());
//						   
						if (time2 > time1) {
							temp = list.get(j);
							list.set(j, list.get(j + 1));
							list.set(j + 1, temp);
						}
					} else {
						if (!list.get(j).getModels()
								.get(list.get(j).getModels().size() - 1)
								.getTime_().equals("null")) {
							list.add(j, list.get(j));
						} else {
							list.add(j, list.get(j + 1));
						}
					}
				}
			}
		}
		return list;
	}

	/**
	 * 判断聊天数据里是否有黑名单的人，如果有则去除掉
	 * 
	 * @param list
	 * @return
	 */
	private List<Main_Chat_Hestory_Message_Model> shaixuan8(
			List<Main_Chat_Hestory_Message_Model> list) {
//		   
		List<Main_Chat_Hestory_Message_Model> list2 = new ArrayList<Main_Chat_Hestory_Message_Model>();
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getModels() != null
					&& !list.get(i).getModels().isEmpty()) {
				if (list.get(i).getModels()
						.get(list.get(i).getModels().size() - 1)
						.getIs_blacklist() != null
						&& !list.get(i).getModels()
								.get(list.get(i).getModels().size() - 1)
								.getIs_blacklist().equals("null")
						&& list.get(i).getModels()
								.get(list.get(i).getModels().size() - 1)
								.getIs_blacklist().equals("0")) {
					list2.add(list.get(i));
				}
			}
		}
		return list2;
	}

	private void listBody() {
		// Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				try {
					map.put("uid", Utils.getUid(getActivity()));
				} catch (Exception e) {
					// TODO: handle exception
				}
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "chat/listBody");
				if (content != null) {
					results = Utils.checkResult_NNN(getActivity(), content);
					//    ("设置界面返回参数是:" + content);
//					   
					if (results != null && results.isRet()) {
						try {
							if (!results.getRetmsg().equals("null")) {
								person_Models = JSONUtils.getListByJsonString(
										results.getRetmsg(),
										Chat_Hestory_person_Model.class);
							}
							handler.sendEmptyMessage(4);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void deleteBody(final String deleteUid) {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				try {
					map.put("uid", Utils.getUid(getActivity()));
					map.put("deleteUid", deleteUid);
				} catch (Exception e) {
					// TODO: handle exception
				}
//				   
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "chat/deleteBody");
				if (content != null) {

					results = Utils.checkResult_NNN(getActivity(), content);
//					   
//							"删除返回的数据是:" + content + " " + results.getRetmsg());
					//    ("设置界面返回参数是:" + content);
					if (results != null && results.isRet()) {
						handler.sendEmptyMessage(7);
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void friendShow() {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", Utils.getUid(getActivity()));
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "chat/friendShow");
				if (content != null) {
					results2 = Utils.checkResult_NNN(getActivity(), content);
					//    ("用户分组列表+朋友返回参数是:" + content);
//					   
					if (results2 != null
							&& !results2.getRetmsg().equals("null")
							&& results2.isRet()) {
						try {
							show_Models = JSONUtils.getListByJsonString(
									results2.getRetmsg(),
									friendShow_Model.class);
							handler.sendEmptyMessage(2);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	class ChatMessageAdapter extends BaseAdapter {
		private DisplayImageOptions options;

		public ChatMessageAdapter() {
			options = new DisplayImageOptions.Builder()
					.showStubImage(R.drawable.ic_stub)
					.showImageForEmptyUri(R.drawable.noimage)
					.showImageOnFail(R.drawable.noimage).cacheInMemory()
					.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5))
					.build();
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return hestory_Message_Models.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return hestory_Message_Models.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		// liaotian_message
		public View getView(int position, View convertView, ViewGroup arg2) {
			// TODO Auto-generated method stub

			LayoutInflater inflater = LayoutInflater.from(getActivity());
			convertView = inflater.inflate(
					R.layout.fragment_after_landing_chat_message, null);
			PaoPao_ImageView liaotian_touxiang_img = (PaoPao_ImageView) convertView
					.findViewById(R.id.liaotian_touxiang_img);
			// PaoPao_Button liaotian_touxiang_num = (PaoPao_Button) convertView
			// .findViewById(R.id.liaotian_touxiang_num);// 头像
			TextView liaotian_name = (TextView) convertView
					.findViewById(R.id.liaotian_name);
			TextView liaotian_message = (TextView) convertView
					.findViewById(R.id.liaotian_message);
			TextView liaotian_time = (TextView) convertView
					.findViewById(R.id.liaotian_time);
			try {
				if (hestory_Message_Models.get(position).getModels() != null
						&& !hestory_Message_Models.get(position).getModels()
								.isEmpty()
						&& hestory_Message_Models.get(position).getModels()
								.size() > 0) {
					liaotian_name.setText(hestory_Message_Models
							.get(position)
							.getModels()
							.get(hestory_Message_Models.get(position)
									.getModels().size() - 1).getNickName());

					if (hestory_Message_Models
							.get(position)
							.getModels()
							.get(hestory_Message_Models.get(position)
									.getModels().size() - 1).getMes()
							.startsWith(yuying)) {
						liaotian_message.setText(""
								+ getActivity().getResources().getString(
										R.string.wx2_6));
					} else {
						new HtmlUtils(getActivity(), liaotian_message,
								hestory_Message_Models
										.get(position)
										.getModels()
										.get(hestory_Message_Models
												.get(position).getModels()
												.size() - 1).getMes(),30)
								.showTextView();
					}

					// liaotian_message.setText(hestory_Message_Models
					// .get(position)
					// .getModels()
					// .get(hestory_Message_Models.get(position)
					// .getModels().size() - 1).getMes());
					liaotian_time.setText(""
							+ hestory_Message_Models
									.get(position)
									.getModels()
									.get(hestory_Message_Models.get(position)
											.getModels().size() - 1).getTime());
//					   
//							"返回的时间是:"
//									+ hestory_Message_Models
//											.get(position)
//											.getModels()
//											.get(hestory_Message_Models
//													.get(position).getModels()
//													.size() - 1).getTime());
					liaotian_touxiang_img.setMessage(hestory_Message_Models
							.get(position).getSum());
					liaotian_touxiang_img
							.setBottomBackgroundResource(hestory_Message_Models
									.get(position)
									.getModels()
									.get(hestory_Message_Models.get(position)
											.getModels().size() - 1).getHead()
									+ Constants.appPhoto4img);
				}
			} catch (Exception e) {
				// TODO: handle exception
			}

			return convertView;
		}
	}
}
